package com.example.tbtx.tbtx.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.tbtx.tbtx.R;
import com.example.tbtx.tbtx.WebViewActivity;
import com.example.tbtx.tbtx.module.MainListResponse;
import com.example.tbtx.tbtx.view.StartBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CompanyDetailActivity extends AppCompatActivity {

    @BindView(R.id.iv_show1)
    ImageView iv_show1;
    @BindView(R.id.iv_show2)
    ImageView iv_show2;
    @BindView(R.id.tv_content)
    TextView tv_content;
    @BindView(R.id.tv_head_name)
    TextView tv_head_name;
    @BindView(R.id.start_bar)
    StartBar start_bar;
    private MainListResponse.DatasBean detail;


    @SuppressLint("CheckResult")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company_detail);
        ButterKnife.bind(this);
        detail = (MainListResponse.DatasBean) getIntent().getSerializableExtra("detail");
        Glide.with(this).load(detail.getImageList().get(0)).into(iv_show1);
        Glide.with(this).load(detail.getImageList().get(1)).into(iv_show2);
        tv_head_name.setText(detail.getEd_name());
        start_bar.setRating(detail.getEd_recommend() / 2);
        tv_content.setText(detail.getEd_detail());
    }

    @OnClick({R.id.iv_back, R.id.tv_web, R.id.tv_download})
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_web:
                intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("url", detail.getLink_address());
                startActivity(intent);
                break;
            case R.id.tv_download:
                if (TextUtils.isEmpty(detail.getDownload_address())) {
                    Toast.makeText(this, "暂无链接", Toast.LENGTH_SHORT).show();
                    return;
                }
                intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("url", detail.getDownload_address());
                startActivity(intent);

                break;
        }
    }
}
